package com.learn.lb.spark.sql


import org.apache.spark.{SparkConf, SparkContext}

/**
 * @author laibo
 * @since 2019/8/9 10:13
 *  wordCount统计
 */
object WordCountSpark {

  def main(args: Array[String]): Unit = {

//    val conf = new SparkConf().setAppName("wc").setMaster("local[2]")
    //通过提交参数指定master url
    val conf = new SparkConf()
    val sc = new SparkContext(conf)
    val filePath = args(0)
    val wordRdd = sc.textFile(filePath)
    val tuples = wordRdd.flatMap(_.split(",")).map((_, 1)).reduceByKey(_ + _).sortBy(_._2, ascending = false)
    tuples.saveAsTextFile(args(1))
    sc.stop()
  }
}
